
use super::solution::Solution;

use std::cmp::Ordering;
impl Solution {
    pub fn minimum_subarray_length(mut nums: Vec<i32>, k: i32) -> i32 {
        let (mut l,mut r)=(0,1);
        let mut ans =usize::MAX;
        while r<=nums.len() {
            let tt=Self::or(&nums[l..r]);
            match tt.cmp(&k) {
                Ordering::Less=>{
                    r+=1;
                },
                Ordering::Equal | Ordering::Greater=>{
                    if ans> (r - l)  {
                        ans= r - l;
                    }
                    l+=1;
                    if l==r{
                        break
                    }
                }
            };

        }
        if ans==usize::MAX {
            -1
        }else{
            ans as i32
        }
    }
    fn or (nums:&[i32])->i32{
        nums.into_iter().fold(0,|acc, &v|{
            acc|v
        })
    }

}